﻿using CloudApiServer.Model;
using Google.Protobuf.WellKnownTypes;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using Org.BouncyCastle.Asn1.X509;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using System.Web;
using System.Web.Caching;
using System.Web.Http;
using System.Web.Routing;
using CloudApiServer.Services;
using static log4net.Appender.RollingFileAppender;

namespace CloudApiServer.Controllers
{
    /// <summary>
    /// 医保挡板管理接口控制器
    /// </summary>
    [RoutePrefix("FsiAdminApi")]
    public class FsiAdminApiController : ApiController
    {
        private readonly FsiAdminApiService _fsiAdminApiService;
        public FsiAdminApiController()
        {
            _fsiAdminApiService = new FsiAdminApiService();
        }
        
        /// <summary>
        /// 新增医保人员信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [Route("InsertPsnInfo")]
        [HttpPost]
        public async Task<IHttpActionResult> InsertPsnInfo(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/InsertPsnInfo";
            try
            {
                var fsiRequest = JsonConvert.DeserializeObject<FsiHeader<outputQueryPsnInfo>>(request.Content.ReadAsStringAsync().Result);
                var (code,data) = await _fsiAdminApiService.InsertPsnInfo(fsiRequest);
                if (code==0)
                {
                    var response = new { code = code, msg = $"新增医保人员信息成功！", data = data };
                    return Json(response);
                }
                else
                {
                    var response = new { code = code, msg = $"新增医保人员信息失败！错误内容：{data}", data = "" };
                    return Json(response);
                }
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var response = new
                {
                    code = -1, msg = $"[{Errnum}]新增医保人员信息失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ",
                    data = ""
                };
                LogHelper.Error(
                    $"[{UrlName}][{Errnum}]新增医保人员信息失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                return Json(response);
            }
        }

        /// <summary>
        /// 删除医保人员信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [Route("DeletePsnInfo")]
        [HttpPost]
        public async Task<IHttpActionResult> DeletePsnInfo(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/DeletePsnInfo";
            try
            {
                var fsiRequest = JsonConvert.DeserializeObject<DeletePsnInfoInput>(request.Content.ReadAsStringAsync().Result);
                var (code,data) = await _fsiAdminApiService.DeletePsnInfo(fsiRequest);
                if (code==0)
                {
                    var response = new { code = code, msg = $"删除医保人员信息成功！", data = data };
                    return Json(response);
                }
                else
                {
                    var response = new { code = code, msg = $"删除医保人员信息失败！错误内容：{data}", data = "" };
                    return Json(response);
                }
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var response = new
                {
                    code = -1, msg = $"[{Errnum}]删除医保人员信息失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ",
                    data = ""
                };
                LogHelper.Error(
                    $"[{UrlName}][{Errnum}]删除医保人员信息失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                return Json(response);
            }
        }



        /// <summary>
        /// 新增处方信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [Route("InsertEpcInfo")]
        [HttpPost]
        public async Task<IHttpActionResult> InsertEpcInfo(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/InsertEpcInfo";
            DataTable dt = new DataTable();
            DataTable dtrxinfo = new DataTable();
            string connectionString = $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
                try
                {
                    if (string.IsNullOrEmpty(request.Content.ReadAsStringAsync().Result))
                    {
                        throw new Exception("入参为空!请检查!");
                    }

                    InsertEpcInfoInput epcInfoInput = JsonConvert.DeserializeObject<InsertEpcInfoInput>(request.Content.ReadAsStringAsync().Result);
                    List<RxDetlList> dataList = new List<RxDetlList>();
                    List<RxDiselist> diseList = new List<RxDiselist>();
                    string psn_no = epcInfoInput.inputJson.Input.data.psn_no;
                    string auth_rxno= epcInfoInput.inputJson.Input.data.auth_rxno;
                    string epc_token = epcInfoInput.inputJson.Input.data.epc_token;
                    string certno="";
                    
                    dataList = epcInfoInput.outputJson.output.rxDetlList;
                    diseList = epcInfoInput.outputJson.output.rxDiseList;
                    
                    await conn.OpenAsync();
                    using (MySqlTransaction transaction = conn.BeginTransaction())
                    {
                        using (MySqlCommand cmd = conn.CreateCommand())
                        {
                            cmd.CommandText = "select * from fsi_PsnInfo where psn_no=@psn_no";
                            cmd.Parameters.AddWithValue("@psn_no", psn_no);
                            using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                            {
                                dt.Load(reader);
                                cmd.Parameters.Clear();
                                if (dt.Rows.Count == 0)
                                {
                                    throw new Exception($"插入处方记录表失败！人员信息校验失败！不存在 {psn_no} 人员信息，请调用人员信息插入接口先插入人员信息后再插入处方信息！");
                                }
                                else
                                {
                                    certno = dt.Rows[0]["certno"].ToString();
                                }
                            }

                            cmd.CommandText = "select * from fsi_prescription where auth_rxno=@auth_rxno";
                            cmd.Parameters.AddWithValue("@auth_rxno", auth_rxno);
                            using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                            {
                                dtrxinfo.Load(reader);
                                cmd.Parameters.Clear();
                                if (dtrxinfo.Rows.Count != 0)
                                {
                                    throw new Exception($"插入处方记录表失败！处方信息校验失败！已存在auth_rxno为 {auth_rxno} 的处方信息，不允许再次插入！");
                                }
                            }
                            /*插入处方汇总信息*/
                            cmd.Transaction = transaction;
                            try
                            {
                                cmd.CommandText = "INSERT INTO `fsi_prescription` (`certno`, `psn_no`, `auth_rxno`, `epc_token`, `expires_in`, `fixmedins_code`, " +
                                    "`fixmedins_name`, `prsc_time`, `dise_codg`, `dise_name`, `valid_end_time`, `hi_rxno`, `rx_trace_code`, `prsc_dept_name`, `rx_type_code`, " +
                                    "`rx_type_name`, `long_rx_flag`, `file_suffix`, `rx_file`, `med_type`, `otp_ipt_flag`, `patn_name`, `patn_age`, `patn_hgt`, `patn_wt`," +
                                    " `gend`, `geso_val`, `nwb_flag`, `nwb_age`, `suck_prd_flag`, `algs_his`, `main_diag_code`, `main_diag_name`, `dise_cond_dscr`, `ID`,rx_exra_attr_code,rx_exra_attr_name) " +
                                    "VALUES (@certno, @psn_no, @auth_rxno, @epc_token," +
                                    " @expires_in, @fixmedins_code, @fixmedins_name, @prsc_time, @dise_codg, @dise_name, @valid_end_time, " +
                                    "@hi_rxno, @rx_trace_code, @prsc_dept_name, @rx_type_code, @rx_type_name, @long_rx_flag, @file_suffix, @rx_file, @med_type, @otp_ipt_flag, " +
                                    "@patn_name, @patn_age, @patn_hgt, @patn_wt, @gend,@geso_val, @nwb_flag, @nwb_age, @suck_prd_flag, @algs_his, @main_diag_code, " +
                                    " @main_diag_name, @dise_cond_dscr, @ID,@rx_exra_attr_code,@rx_exra_attr_name )";
                                cmd.Parameters.AddWithValue("@certno", certno);
                                cmd.Parameters.AddWithValue("@psn_no", psn_no);
                                cmd.Parameters.AddWithValue("@auth_rxno", auth_rxno);
                                cmd.Parameters.AddWithValue("@epc_token", epc_token);
                                cmd.Parameters.AddWithValue("@expires_in", epcInfoInput.outputJson.output.data.prsc_time);
                                cmd.Parameters.AddWithValue("@fixmedins_code", epcInfoInput.outputJson.output.data.fixmedins_code);
                                cmd.Parameters.AddWithValue("@fixmedins_name", epcInfoInput.outputJson.output.data.fixmedins_name);
                                cmd.Parameters.AddWithValue("@prsc_time", epcInfoInput.outputJson.output.data.prsc_time);
                                cmd.Parameters.AddWithValue("@dise_codg", epcInfoInput.outputJson.output.rxOtpinfo.dise_codg);
                                cmd.Parameters.AddWithValue("@dise_name", epcInfoInput.outputJson.output.rxOtpinfo.dise_name);
                                cmd.Parameters.AddWithValue("@valid_end_time", epcInfoInput.outputJson.output.data.valid_end_time);
                                cmd.Parameters.AddWithValue("@hi_rxno", epcInfoInput.outputJson.output.data.hi_rxno);
                                cmd.Parameters.AddWithValue("@rx_trace_code", epcInfoInput.outputJson.output.data.rx_trace_code);
                                cmd.Parameters.AddWithValue("@prsc_dept_name", epcInfoInput.outputJson.output.data.prsc_dept_name);
                                cmd.Parameters.AddWithValue("@rx_type_code", epcInfoInput.outputJson.output.data.rx_type_code);
                                cmd.Parameters.AddWithValue("@rx_type_name", epcInfoInput.outputJson.output.data.rx_type_name);
                                cmd.Parameters.AddWithValue("@long_rx_flag", epcInfoInput.outputJson.output.data.long_rx_flag);
                                cmd.Parameters.AddWithValue("@file_suffix", epcInfoInput.outputJson.output.data.file_suffix);
                                cmd.Parameters.AddWithValue("@rx_file", epcInfoInput.outputJson.output.data.rx_file);
                                cmd.Parameters.AddWithValue("@med_type", epcInfoInput.outputJson.output.rxOtpinfo.med_type);
                                cmd.Parameters.AddWithValue("@otp_ipt_flag", epcInfoInput.outputJson.output.rxOtpinfo.otp_ipt_flag);
                                cmd.Parameters.AddWithValue("@patn_name", epcInfoInput.outputJson.output.rxOtpinfo.patn_name);
                                cmd.Parameters.AddWithValue("@patn_age", epcInfoInput.outputJson.output.rxOtpinfo.patn_age);
                                cmd.Parameters.AddWithValue("@patn_hgt", epcInfoInput.outputJson.output.rxOtpinfo.patn_hgt);
                                cmd.Parameters.AddWithValue("@patn_wt", epcInfoInput.outputJson.output.rxOtpinfo.patn_wt);
                                cmd.Parameters.AddWithValue("@geso_val", epcInfoInput.outputJson.output.rxOtpinfo.geso_val);
                                cmd.Parameters.AddWithValue("@nwb_flag", epcInfoInput.outputJson.output.rxOtpinfo.nwb_flag);
                                cmd.Parameters.AddWithValue("@nwb_age", epcInfoInput.outputJson.output.rxOtpinfo.nwb_age);
                                cmd.Parameters.AddWithValue("@suck_prd_flag", epcInfoInput.outputJson.output.rxOtpinfo.suck_prd_flag);
                                cmd.Parameters.AddWithValue("@algs_his", epcInfoInput.outputJson.output.rxOtpinfo.algs_his);
                                cmd.Parameters.AddWithValue("@main_diag_code", epcInfoInput.outputJson.output.rxOtpinfo.main_diag_code);
                                cmd.Parameters.AddWithValue("@main_diag_name", epcInfoInput.outputJson.output.rxOtpinfo.main_diag_name);
                                cmd.Parameters.AddWithValue("@dise_cond_dscr", epcInfoInput.outputJson.output.rxOtpinfo.dise_cond_dscr);
                                cmd.Parameters.AddWithValue("@rx_exra_attr_code", "03");
                                cmd.Parameters.AddWithValue("@rx_exra_attr_name", "普通处方默认");
                                await cmd.ExecuteNonQueryAsync();
                                cmd.Parameters.Clear();
                            }
                            catch (Exception ex)
                            {
                                transaction.Rollback();
                                throw new Exception($"插入处方记录表失败！处方汇总信息插入失败！错误内容：{ex.Message}");
                            }
                            
                            string error="";
                            foreach (var item in dataList)
                            {
                                try
                                {
                                    cmd.CommandText = "INSERT INTO `fsi_prescription_detail` (`psn_no`, `auth_rxno`, `med_list_codg`, `fixmedins_hilist_id`, " +
                                        "`hosp_prep_flag`, `rx_item_type_code`, `rx_item_type_name`, `tcmdrug_type_name`, `tcmdrug_type_code`, `tcmherb_foote`, `medn_type_code`, " +
                                        "`medn_type_name`, `main_medc_flag`, `urgt_flag`, `bas_medn_flag`, `imp_drug_flag`, `drug_prodname`, `drug_genname`, `drug_dosform`, `drug_spec`," +
                                        " `prdr_name`, `drug_cnt`, `medc_way_codg`, `medc_way_dscr`, `medc_endtime`, `medc_days`, `medc_begntime`, `drug_dosunt`, `sin_doscnt`, `sin_dosunt`," +
                                        " `used_frqu_codg`, `used_frqu_name`, `drug_totlcnt`, `drug_totlnt_emp`, `own_expense_flag`, `hi_nego_drug_flag`, `refer_d_channel_flag`, " +
                                        "`bidding_drug_flag`, `hosp_appr_flag`,take_drug_flag,otc_flag,self_pay_rea,real_dscr) VALUES (@psn_no, @auth_rxno,@med_list_codg,@fixmedins_hilist_id, @hosp_prep_flag, @rx_item_type_code,@rx_item_type_name, " +
                                        "@tcmdrug_type_name, @tcmdrug_type_code,@tcmherb_foote, @medn_type_code, @medn_type_name, @main_medc_flag, @urgt_flag, @bas_medn_flag, @imp_drug_flag," +
                                        " @drug_prodname, @drug_genname, @drug_dosform, @drug_spec, @prdr_name , @drug_cnt, @medc_way_codg, @medc_way_dscr, @medc_endtime, @medc_days, @medc_begntime, " +
                                        "@drug_dosunt, @sin_doscnt,@sin_dosunt, @used_frqu_codg, @used_frqu_name, @drug_totlcnt, @drug_totlnt_emp, @own_expense_flag,@hi_nego_drug_flag, @refer_d_channel_flag, " +
                                        "@bidding_drug_flag, @hosp_appr_flag,@take_drug_flag,@otc_flag,@self_pay_rea,@real_dscr)";

                                    cmd.Parameters.AddWithValue("@psn_no", psn_no);
                                    cmd.Parameters.AddWithValue("@auth_rxno", auth_rxno);
                                    cmd.Parameters.AddWithValue("@med_list_codg", item.med_list_codg);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", item.fixmedins_hilist_id);
                                    cmd.Parameters.AddWithValue("@hosp_prep_flag", item.hosp_prep_flag);
                                    cmd.Parameters.AddWithValue("@rx_item_type_code", item.rx_item_type_code);
                                    cmd.Parameters.AddWithValue("@rx_item_type_name", item.rx_item_type_name);
                                    cmd.Parameters.AddWithValue("@tcmdrug_type_name", item.tcmdrug_type_name);
                                    cmd.Parameters.AddWithValue("@tcmdrug_type_code", item.tcmdrug_type_code);
                                    cmd.Parameters.AddWithValue("@tcmherb_foote", item.tcmherb_foote);
                                    cmd.Parameters.AddWithValue("@medn_type_code", item.medn_type_code);
                                    cmd.Parameters.AddWithValue("@medn_type_name", item.medn_type_name);
                                    cmd.Parameters.AddWithValue("@main_medc_flag", item.main_medc_flag);
                                    cmd.Parameters.AddWithValue("@urgt_flag", item.urgt_flag);
                                    cmd.Parameters.AddWithValue("@bas_medn_flag", item.bas_medn_flag);
                                    cmd.Parameters.AddWithValue("@imp_drug_flag", item.imp_drug_flag);
                                    cmd.Parameters.AddWithValue("@drug_prodname", item.drug_prodname);
                                    cmd.Parameters.AddWithValue("@drug_genname", item.drug_genname);
                                    cmd.Parameters.AddWithValue("@drug_dosform", item.drug_dosform);
                                    cmd.Parameters.AddWithValue("@drug_spec", item.drug_spec);
                                    cmd.Parameters.AddWithValue("@prdr_name", item.prdr_name);
                                    cmd.Parameters.AddWithValue("@drug_cnt", item.drug_cnt);
                                    cmd.Parameters.AddWithValue("@medc_way_codg", item.medc_way_codg);
                                    cmd.Parameters.AddWithValue("@medc_way_dscr", item.medc_way_dscr);
                                    cmd.Parameters.AddWithValue("@medc_endtime", item.medc_endtime);
                                    cmd.Parameters.AddWithValue("@medc_days", item.medc_days);
                                    cmd.Parameters.AddWithValue("@medc_begntime", item.medc_begntime);
                                    cmd.Parameters.AddWithValue("@drug_dosunt", item.drug_dosunt);
                                    cmd.Parameters.AddWithValue("@sin_doscnt", item.sin_doscnt);
                                    cmd.Parameters.AddWithValue("@sin_dosunt", item.sin_dosunt);
                                    cmd.Parameters.AddWithValue("@used_frqu_codg", item.used_frqu_codg);
                                    cmd.Parameters.AddWithValue("@used_frqu_name", item.used_frqu_name);
                                    cmd.Parameters.AddWithValue("@drug_totlcnt", item.drug_totlcnt);
                                    cmd.Parameters.AddWithValue("@drug_totlnt_emp", item.drug_totlnt_emp);
                                    cmd.Parameters.AddWithValue("@own_expense_flag", item.own_expense_flag);
                                    cmd.Parameters.AddWithValue("@hi_nego_drug_flag", item.hi_nego_drug_flag);
                                    cmd.Parameters.AddWithValue("@refer_d_channel_flag", item.refer_d_channel_flag);
                                    cmd.Parameters.AddWithValue("@bidding_drug_flag", item.bidding_drug_flag);
                                    cmd.Parameters.AddWithValue("@hosp_appr_flag", item.hosp_appr_flag);
                                    cmd.Parameters.AddWithValue("@take_drug_flag", item.take_drug_flag);
                                    cmd.Parameters.AddWithValue("@otc_flag", item.otc_flag);
                                    cmd.Parameters.AddWithValue("@self_pay_rea", item.self_pay_rea);
                                    cmd.Parameters.AddWithValue("@real_dscr", item.real_dscr);
                                    await cmd.ExecuteNonQueryAsync();
                                    cmd.Parameters.Clear();
                                }
                                catch (Exception ex)
                                {
                                    error = error + $" 【{item.drug_genname}({item.drug_prodname})/{item.drug_spec}】插入处方记录表失败！处方明细信息插入失败！：" + ex.Message + "|";
                                    cmd.Parameters.Clear();
                                }
                            }
                            foreach (var item in diseList)
                            {
                                try
                                {
                                    cmd.CommandText =
                                        "INSERT INTO `fsi_prescription_diseinfo` (`psn_no`, `auth_rxno`, `diag_type`, `maindiag_flag`, `diag_srt_no`, `diag_code`, `diag_name`, `tcm_dise_code`, `tcm_dise_name`, `tcmsymp_code`, `tcmsymp`)" +
                                        " VALUES (@psn_no, @auth_rxno, @diag_type, @maindiag_flag, @diag_srt_no, @diag_code, @diag_name,@tcm_dise_code, @tcm_dise_name,@tcmsymp_code, @tcmsymp)";

                                    cmd.Parameters.AddWithValue("@psn_no", psn_no);
                                    cmd.Parameters.AddWithValue("@auth_rxno", auth_rxno);
                                    cmd.Parameters.AddWithValue("@diag_type", item.diag_type);
                                    cmd.Parameters.AddWithValue("@maindiag_flag", item.maindiag_flag);
                                    cmd.Parameters.AddWithValue("@diag_srt_no", item.diag_srt_no);
                                    cmd.Parameters.AddWithValue("@diag_code", item.diag_code);
                                    cmd.Parameters.AddWithValue("@diag_name", item.diag_name);
                                    cmd.Parameters.AddWithValue("@tcm_dise_code", item.tcm_dise_code);
                                    cmd.Parameters.AddWithValue("@tcm_dise_name", item.tcm_dise_name);
                                    cmd.Parameters.AddWithValue("@tcmsymp_code", item.tcmsymp_code);
                                    cmd.Parameters.AddWithValue("@tcmsymp", item.tcmsymp);
                                    await cmd.ExecuteNonQueryAsync();
                                    cmd.Parameters.Clear();
                                }
                                catch (Exception ex)
                                {
                                    error = error + $" 【{item.diag_code}({item.diag_name})】插入处方诊断列表失败！处方诊断信息插入失败！：" + ex.Message + "|";
                                    cmd.Parameters.Clear();
                                }
                            }
                            if (error != "")
                            {
                                transaction.Rollback();
                                throw new Exception(error);
                            }
                            else
                            {
                                transaction.Commit();
                                //transaction.Rollback();
                                return Json(new { code = 0, msg = "", data = "插入成功!" });
                            }
                        }
                    }
                        
                }
                catch (Exception ex)
                {
                    string Errnum = LogHelper.GetErrornumber();
                    var response = new { code = -1, msg = $"[{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ", data = "" };
                    LogHelper.Error($"[{UrlName}][{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                    return Json(response);
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        await conn.CloseAsync();
                    }
                }
            }
        }
        
        /// <summary>
        /// 删除处方信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [Route("DeleteEpcInfo")]
        [HttpPost]
        public async Task<IHttpActionResult> DeleteEpcInfo(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/DeleteEpcInfo";

            string connectionString = $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
                try
                {
                    if (string.IsNullOrEmpty(request.Content.ReadAsStringAsync().Result))
                    {
                        var response = new { code = 100, msg = $"参数校验失败：入参为空!请检查!", data = "" };
                        return Json(response);
                    }
                    var fsiRequest = JsonConvert.DeserializeObject<DeleteEpcInfoInput>(request.Content.ReadAsStringAsync().Result);
                    if (string.IsNullOrEmpty(fsiRequest.auth_rxno))
                    {
                        var response = new { code = 100, msg = $"参数校验失败：传入的处方授权编号auth_rxno为空!", data = "" };
                        return Json(response);
                    }
                    await conn.OpenAsync();
                    DataTable dt = new DataTable();
                    using (MySqlTransaction transaction = conn.BeginTransaction())
                    {
                        using (MySqlCommand cmd = conn.CreateCommand())
                        {
                            cmd.CommandText = "select * from fsi_prescription where auth_rxno=@auth_rxno";
                            cmd.Parameters.AddWithValue("@auth_rxno", fsiRequest.auth_rxno);
                            using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                            {
                                dt.Load(reader);
                                cmd.Parameters.Clear();
                                if (dt.Rows.Count > 0)
                                {
                                    cmd.Transaction = transaction;
                                    try
                                    {
                                        cmd.CommandText = "delete from fsi_prescription where auth_rxno=@auth_rxno";
                                        cmd.Parameters.AddWithValue("@auth_rxno", fsiRequest.auth_rxno);
                                        await cmd.ExecuteNonQueryAsync();
                                        cmd.Parameters.Clear();
                                        cmd.CommandText = "delete from fsi_prescription_detail where auth_rxno=@auth_rxno";
                                        cmd.Parameters.AddWithValue("@auth_rxno", fsiRequest.auth_rxno);
                                        await cmd.ExecuteNonQueryAsync();
                                        cmd.Parameters.Clear();
                                        cmd.CommandText = "delete from fsi_prescription_diseinfo where auth_rxno=@auth_rxno";
                                        cmd.Parameters.AddWithValue("@auth_rxno", fsiRequest.auth_rxno);
                                        await cmd.ExecuteNonQueryAsync();
                                        cmd.Parameters.Clear();
                                        transaction.Commit();
                                        var response = new { code = 0, msg = "", data = "删除医保处方信息记录成功!" };
                                        return Json(response);
                                    }
                                    catch (Exception ex)
                                    {
                                        transaction.Rollback();
                                        throw;
                                    }
                                }
                                else
                                {
                                    var response = new { code = 100, msg = $"业务参数校验失败：删除医保处方信息记录失败！传入的处方授权编号auth_rxno:{fsiRequest.auth_rxno}查询到{dt.Rows.Count}条相关数据！无需删除！", data = "" };
                                    return Json(response);
                                }
                            }

                        }
                    }                     
                }
                catch (Exception ex)
                {
                    string Errnum = LogHelper.GetErrornumber();
                    var response = new { code = -1, msg = $"[{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ", data = "" };
                    LogHelper.Error($"[{UrlName}][{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                    return Json(response);
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        await conn.CloseAsync();
                    }
                }
            }
        }

        /// <summary>
        /// 新增事前事中违规商品控制
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [Route("InsertRiskconserviceProductInfo")]
        [HttpPost]
        public async Task<IHttpActionResult> InsertRiskconserviceProductInfo(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/InsertRiskconserviceProductInfo";
            try
            {
                var fsiRequest = JsonConvert.DeserializeObject<InsertRiskconserviceProductInfoInput>(request.Content.ReadAsStringAsync().Result);
                var (code,data) = await _fsiAdminApiService.InsertRiskconserviceProductInfo(fsiRequest);
                if (code==0)
                {
                    var response = new { code = code, msg = $"新增事前事中违规商品成功！", data = data };
                    return Json(response);
                }
                else
                {
                    var response = new { code = code, msg = $"新增事前事中违规商品失败！错误内容：{data}", data = "" };
                    return Json(response);
                }
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var response = new
                {
                    code = -1, msg = $"[{Errnum}]新增事前事中违规商品失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ",
                    data = ""
                };
                LogHelper.Error(
                    $"[{UrlName}][{Errnum}]新增事前事中违规商品失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                return Json(response);
            }
        }


        /// <summary>
        /// 删除事前事中违规商品控制
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [Route("DeleteRiskconserviceProductInfo")]
        [HttpPost]
        public async Task<IHttpActionResult> DeleteRiskconserviceProductInfo(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/DeleteRiskconserviceProductInfo";
            try
            {
                var fsiRequest = JsonConvert.DeserializeObject<InsertRiskconserviceProductInfoInput>(request.Content.ReadAsStringAsync().Result);
                var (code,data) = await _fsiAdminApiService.DeleteRiskconserviceProductInfo(fsiRequest);
                if (code==0)
                {
                    var response = new { code = code, msg = $"删除事前事中违规商品成功！", data = data };
                    return Json(response);
                }
                else
                {
                    var response = new { code = code, msg = $"删除事前事中违规商品失败！错误内容：{data}", data = "" };
                    return Json(response);
                }
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var response = new
                {
                    code = -1, msg = $"[{Errnum}]删除事前事中违规商品失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ",
                    data = ""
                };
                LogHelper.Error(
                    $"[{UrlName}][{Errnum}]删除事前事中违规商品失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                return Json(response);
            }
        }

        /// <summary>
        /// 查询医保表相关的数据
        /// </summary>
        /// <param name="pwd"></param>
        /// <param name="tablename"></param>
        /// <param name="pagesize"></param>
        /// <param name="nowpage"></param>
        /// <returns></returns>
        [Route("SelectFsiTableData")]
        [HttpGet]
        public async Task<IHttpActionResult> SelectFsiTableData(string pwd,string tablename, int? pagesize = 10, int? nowpage = 1)
        {

            string UrlName = "/FsiAdminApi/SelectFsiTableData";
            if (nowpage <= 0 || pagesize <= 0)
            {

                var response = new { code = 100, msg = $"服务端数据校验不通过：分页参数异常！不允许小于等于0的值传入！当前页传入:{nowpage} 每页大小传入：{pagesize}", data = "" };
                LogHelper.Info($"[{UrlName}]参数异常！分页参数异常！当前页传入:{nowpage} 每页大小传入：{pagesize}！");
                return Json(response);
            }
            //当前分页的最大页数
            int maxpage = (int)((nowpage - 1) * pagesize);

            string connectionString = $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
                try
                {
                    bool isAuth = await PublicMethod.ApiPasswordAuth("SelectFsiTableData", pwd);
                    if (isAuth != true)
                    {
                        var response = new { code = 100, msg = $"该接口需要管理员鉴权，鉴权密钥错误！", data = "" };
                        return Json(response);
                    }
                    await conn.OpenAsync();
                    using (MySqlCommand cmd = conn.CreateCommand())
                    {

                        cmd.CommandText = $"select * from {tablename} limit @maxpage,@pagesize";
                        cmd.Parameters.AddWithValue("@maxpage", maxpage);
                        cmd.Parameters.AddWithValue("@pagesize", pagesize);
                        using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                        {
                            DataTable dt = new DataTable();
                            dt.Load(reader);
                            var response = new { code = 0, msg = "", data = dt };
                            LogHelper.Info($"[{UrlName}]请求成功！");
                            return Json(response);
                        }
                    }
                }
                catch (Exception ex)
                {
                    string Errnum = LogHelper.GetErrornumber();
                    var response = new { code = -1, msg = $"[{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace}", data = "" };
                    LogHelper.Error($"[{UrlName}][{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                    return Json(response);
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        await conn.CloseAsync(); 
                    }
                }
            }
        }
        
        /// <summary>
        /// 生成处方PDF文件（7203 7204转换）
        /// </summary>
        /// <param name="request">处方中心入参</param>
        /// <param name="infno">接口转换类型 7203Output 7204Input</param>
        /// <returns></returns>
        [Route("GeneratePrescriptionFile")]
        [HttpPost]
        public  IHttpActionResult GeneratePrescriptionFile(HttpRequestMessage request,string infno)
        {
            string UrlName = "/FsiAdminApi/GeneratePrescriptionFile";
            try
            {
                string filePath = AppDomain.CurrentDomain.BaseDirectory+"\\file\\PDF";
                string filename = "YBPDF" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".pdf";
                if (string.IsNullOrEmpty(request.Content.ReadAsStringAsync().Result))
                {
                    var response = new { code = 100, msg = $"参数校验失败：入参为空!请检查!", data = "" };
                    return Json(response);
                }

                if (infno=="7203Output")
                {
                    var fsiRequest = JsonConvert.DeserializeObject<FsiHeader<outputDataOpsp7203>>(request.Content.ReadAsStringAsync().Result);
                    string rxFile = fsiRequest.output.data.rx_file;
                    if (!string.IsNullOrEmpty(rxFile))
                    {
                        bool state;
                        string path = PublicMethod.Base64StringToFile(out state,rxFile, filePath,filename);
                        if (state==true)
                        {
                            var output = new
                            {
                                code = 0,
                                msg = "",
                                data = new OutputGeneratePrescriptionFile
                                {
                                    prescription_file_Datetime=DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                    prescription_file_name=filename,
                                    prescription_file_path=path
                                }
                            };
                            return Json(output);
                        }
                        else
                        {
                            throw new Exception(path);
                        }
                    }
                    else
                    {
                        var response = new { code = 100, msg = $"参数校验失败：传入的转换类型{infno}入参的rx_file参数为空!请检查入参是否为浙江省医保7203出参报文!", data = "" };
                        return Json(response);
                    }

                }
                else if (infno == "7204Input")
                {
                    var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputOpsp7204Request>>(request.Content.ReadAsStringAsync().Result);
                    string rxFile = fsiRequest.Input.data.rx_file;
                    if (!string.IsNullOrEmpty(rxFile))
                    {
                        bool state;
                        string path = PublicMethod.Base64StringToFile(out state, rxFile, filePath, filename);
                        if (state == true)
                        {
                            var output = new
                            {
                                code = 0,
                                msg = "",
                                data = new OutputGeneratePrescriptionFile
                                {
                                    prescription_file_Datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                    prescription_file_name = filename,
                                    prescription_file_path = path
                                }
                            };
                            return Json(output);
                        }
                        else
                        {
                            throw new Exception(path);
                        }
                    }
                    else
                    {
                        var response = new { code = 100, msg = $"参数校验失败：传入的转换类型{infno}入参的rx_file参数为空!请检查入参是否为浙江省医保7203出参报文!", data = "" };
                        return Json(response);
                    }
                }
                else
                {
                    var response = new { code = 100, msg = $"参数校验失败：传入的{infno}转换类型未被定义！请检查!", data = "" };
                    return Json(response);
                }
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var response = new { code = -1, msg = $"[{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ", data = "" };
                LogHelper.Error($"[{UrlName}][{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                return Json(response);
            }
        }

        
        /// <summary>
        /// 新增医保人员待遇享受检查
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [Route("InsertPsnPriorityInfo")]
        [HttpPost]
        public async Task<IHttpActionResult> InsertPsnPriorityInfo(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/InsertPsnPriorityInfo";
            try
            {
                var fsiRequest =
                    JsonConvert.DeserializeObject<FsiHeader<OutputQueryPsnPriorityInfo>>(request.Content
                        .ReadAsStringAsync().Result);
                var (code,data) = await _fsiAdminApiService.InsertPsnPriorityInfo(fsiRequest);
                if (code==0)
                {
                    var response = new { code = code, msg = $"新增人员待遇享受检查成功！", data = data };
                    return Json(response);
                }
                else
                {
                    var response = new { code = code, msg = $"新增人员待遇享受检查失败！错误内容：{data}", data = "" };
                    return Json(response);
                }
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var response = new
                {
                    code = -1, msg = $"[{Errnum}]新增人员待遇享受检查失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ",
                    data = ""
                };
                LogHelper.Error(
                    $"[{UrlName}][{Errnum}]新增人员待遇享受检查失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                return Json(response);
            }
        }

        /// <summary>
        /// 删除医保人员待遇享受检查
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [Route("DeletePsnPriorityInfo")]
        [HttpPost]
        public async Task<IHttpActionResult> DeletePsnPriorityInfo(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/DeletePsnPriorityInfo";
            try
            {
                var fsiRequest =
                    JsonConvert.DeserializeObject<DeletePsnPriorityInfoInput>(request.Content
                        .ReadAsStringAsync().Result);
                var (code,data) = await _fsiAdminApiService.DeletePsnPriorityInfo(fsiRequest);
                if (code==0)
                {
                    var response = new { code = code, msg = $"删除人员待遇享受检查成功！", data = data };
                    return Json(response);
                }
                else
                {
                    var response = new { code = code, msg = $"删除人员待遇享受检查失败！错误内容：{data}", data = "" };
                    return Json(response);
                }
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var response = new
                {
                    code = -1, msg = $"[{Errnum}]删除人员待遇享受检查失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ",
                    data = ""
                };
                LogHelper.Error(
                    $"[{UrlName}][{Errnum}]删除人员待遇享受检查失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                return Json(response);
            }
        }
        
        /// <summary>
        /// 新增两定机构信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [Route("InsertFixmedins")]
        [HttpPost]
        public async Task<IHttpActionResult> InsertFixmedins(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/InsertFixmedins";
            try
            {
                var fsiRequest =
                    JsonConvert.DeserializeObject<FsiHeader<OutputQueryFixMedIns>>(request.Content
                        .ReadAsStringAsync().Result);
                var (code,data) = await _fsiAdminApiService.InsertFixmedins(fsiRequest);
                if (code==0)
                {
                    var response = new { code = code, msg = $"新增两定机构数据成功！", data = data };
                    return Json(response);
                }
                else
                {
                    var response = new { code = code, msg = $"新增两定机构数据失败！错误内容：{data}", data = "" };
                    return Json(response);
                }
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var response = new
                {
                    code = -1, msg = $"[{Errnum}]新增两定机构数据失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ",
                    data = ""
                };
                LogHelper.Error(
                    $"[{UrlName}][{Errnum}]新增两定机构数据失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                return Json(response);
            }
        }
        
        
        /// <summary>
        /// 删除两定机构信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [Route("DeleteFixmedins")]
        [HttpPost]
        public async Task<IHttpActionResult> DeleteFixmedins(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/DeleteFixmedins";
            try
            {
                var fsiRequest =
                    JsonConvert.DeserializeObject<DeleteFixmedinsInput>(request.Content
                        .ReadAsStringAsync().Result);
                var (code,data) = await _fsiAdminApiService.DeleteFixmedins(fsiRequest);
                if (code==0)
                {
                    var response = new { code = code, msg = $"删除两定机构信息成功！", data = data };
                    return Json(response);
                }
                else
                {
                    var response = new { code = code, msg = $"删除两定机构信息失败！错误内容：{data}", data = "" };
                    return Json(response);
                }
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var response = new
                {
                    code = -1, msg = $"[{Errnum}]删除两定机构信息失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ",
                    data = ""
                };
                LogHelper.Error(
                    $"[{UrlName}][{Errnum}]删除两定机构信息失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                return Json(response);
            }
        }
        
        /// <summary>
        /// 新增人员慢特病备案
        /// </summary>
        /// <param name="request"></param>
        /// <param name="psn_no">人员编号</param>
        /// <returns></returns>
        [Route("InsertPsnOpspReg")]
        [HttpPost]
        public async Task<IHttpActionResult> InsertPsnOpspReg(HttpRequestMessage request,string psn_no)
        {
            string UrlName = "/FsiAdminApi/InsertPsnOpspReg";
            try
            {
                var fsiRequest =
                    JsonConvert.DeserializeObject<FsiHeader<OutputQueryPsnOpspReg>>(request.Content
                        .ReadAsStringAsync().Result);
                var (code,data) = await _fsiAdminApiService.InsertPsnOpspReg(fsiRequest,psn_no);
                if (code==0)
                {
                    var response = new { code = code, msg = $"新增人员慢特病备案成功！", data = data };
                    return Json(response);
                }
                else
                {
                    var response = new { code = code, msg = $"新增人员慢特病备案失败！错误内容：{data}", data = "" };
                    return Json(response);
                }
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var response = new
                {
                    code = -1, msg = $"[{Errnum}]新增人员慢特病备案失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ",
                    data = ""
                };
                LogHelper.Error(
                    $"[{UrlName}][{Errnum}]新增人员慢特病备案失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                return Json(response);
            }
        }
        
        
        /// <summary>
        /// 删除人员慢特病备案
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [Route("DeletePsnOpspReg")]
        [HttpPost]
        public async Task<IHttpActionResult> DeletePsnOpspReg(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/DeletePsnOpspReg";
            try
            {
                var fsiRequest =
                    JsonConvert.DeserializeObject<DeletePsnOpspRegInput>(request.Content
                        .ReadAsStringAsync().Result);
                var (code,data) = await _fsiAdminApiService.DeletePsnOpspReg(fsiRequest);
                if (code==0)
                {
                    var response = new { code = code, msg = $"删除人员慢特病备案成功！", data = data };
                    return Json(response);
                }
                else
                {
                    var response = new { code = code, msg = $"删除人员慢特病备案失败！错误内容：{data}", data = "" };
                    return Json(response);
                }
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var response = new
                {
                    code = -1, msg = $"[{Errnum}]删除人员慢特病备案失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ",
                    data = ""
                };
                LogHelper.Error(
                    $"[{UrlName}][{Errnum}]删除人员慢特病备案失败！服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                return Json(response);
            }
        }

        /// <summary>
        /// 获取设置配置
        /// </summary>
        /// <returns></returns>
        [Route("GetSettingConfig")]
        [HttpGet]
        public IHttpActionResult GetSettingConfig()
        {
            string UrlName = "/FsiAdminApi/GetSettingConfig";
            try
            {
                var response = new
                {
                    code = 0,
                    msg = "",
                    data = new
                    {
                        epcTokenInfo= new
                        {
                            appId=FsiEpcTokeninfo.appId,
                            appSecret=FsiEpcTokeninfo.appSecret,
                            privateKey = FsiEpcTokeninfo.privateKey,
                            publicKey = FsiEpcTokeninfo.publicKey
                        },
                        cardnoInfo = new
                        {
                            defautCardNo = FsiDatainfo.Defautlcardno,
                            eccCodeCardNo = FsiDatainfo.Ecccodecardno,
                            jiangsuDefautlcardno = FsiDatainfo.JiangsuDefautlcardno,
                        },
                        apiStateInfo = new
                        {
                            stateNeusJiangsuApi = FsiDatainfo.stateNeusJiangsuApi,
                            stateFsiApi = FsiDatainfo.stateFsiApi,
                            stateFsiEpcApi = FsiDatainfo.stateFsiEpcApi,
                            statesSignon = FsiDatainfo.statesignon,
                            stateShandongBinzhouApi = FsiDatainfo.stateShandongBinzhouApi,
                            stateShandongDarewayApi = FsiDatainfo.stateShandongDarewayApi,
                            stateShandongJxcApi = FsiDatainfo.stateShandongJxcApi,
                            stateLocalApiInInternal = FsiDatainfo.stateLocalApiInInternal
                        },
                        acctPayInfo = new
                        {
                            fundPaySumamt = FsiDatainfo.fund_pay_sumamt,
                            psnCashPay = FsiDatainfo.psn_cash_pay,
                            acctPay = FsiDatainfo.acct_pay,
                            clcYearAcctPay = FsiDatainfo.clcYearAcctPay,
                            crtYearAcctPay =FsiDatainfo.crtYearAcctPay,
                            acctMulaidPay = FsiDatainfo.acct_mulaid_pay
                        },
                        otherPayInfo = new
                        {
                            cvlservPay = FsiDatainfo.cvlserv_pay,
                            hifdmPay = FsiDatainfo.hifdm_pay,
                            hifmiPay = FsiDatainfo.hifmi_pay,
                            actPayDedc = FsiDatainfo.act_pay_dedc,
                            hifobPay = FsiDatainfo.hifob_pay,
                            othPay = FsiDatainfo.oth_pay,
                            hifesPay =FsiDatainfo.hifes_pay,
                            fulamtOwnpayAmt = FsiDatainfo.fulamt_ownpay_amt,
                            hospPartAmt = FsiDatainfo.hosp_part_amt,
                            inscpScpAmt = FsiDatainfo.inscp_scp_amt,
                            mafPay = FsiDatainfo.maf_pay,
                            overlmtSelfpay = FsiDatainfo.overlmt_selfpay,
                            preselfpayAmt = FsiDatainfo.preselfpay_amt
                        }
                    }
                };
                return Json(response);    
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var response = new { code = -1, msg = $"[{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ", data = "" };
                LogHelper.Error($"[{UrlName}][{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                return Json(response);
            }
        }
    }
}
